home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
tcppack
/
tcppackb.lzh
/
src
/
samples
/
statistic.c
< prev
Wrap
C/C++ Source or Header
|
1995-11-07
|
9KB
|
358 lines
/*
* statistic.c - print ether+ statistics
*
* Copyright (C) 1994 Tomoaki Tada/F.C.T.
*/
static char *rcsid = "$Id: statistic.c,v 1.3 1994/08/04 05:11:26 Niggle Exp Niggle $";
/*
* $Log: statistic.c,v $
* Revision 1.3 1994/08/04 05:11:26 Niggle
* deviceé¬æ╢ì▌é╡é╚éóÅΩìçé╠ò\Īé≡ò╧ìX
*
* Revision 1.2 1994/07/23 01:01:50 Niggle
* òíÉöé╠EtherDriveré╔æ╬ë₧
*
* Revision 1.1 1994/06/22 02:01:37 Niggle
* Initial revision
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/scsi.h>
#include"etherdrv.h"
struct sts
{
char *name;
int size;
int offset;
};
#define NUM_OF_SS (32)
#define SS_TOP (98)
struct sts SCSI_STAT[NUM_OF_SS] =
{
{" scsi_int", 4, SS_TOP},
{" select", 4, SS_TOP + 4},
{" reset", 4, SS_TOP + 8},
{" cmmd_ethwrt", 4, SS_TOP + 12},
{" bus_busy", 4, SS_TOP + 16},
{" arbitrate", 4, SS_TOP + 20},
{" reconnects", 4, SS_TOP + 24},
{" recon_rcvs", 4, SS_TOP + 36},
{" recon_sends", 4, SS_TOP + 40},
{" discon_pre", 4, SS_TOP + 28},
{" discon_post", 4, SS_TOP + 32},
{" discon_sel", 2, SS_TOP + 82},
{" no_busfree", 2, 186 + 2 * 12},
{" lost_arb", 2, SS_TOP + 84},
{" toss_packet", 4, SS_TOP + 44},
{" recon_ok", 2, SS_TOP + 48},
{" cmmd_ethrst", 2, SS_TOP + 54},
{" cmmd_sndmsg", 2, SS_TOP + 56},
{" cmmd_getmsg", 2, SS_TOP + 58},
{" cmmd_inq", 2, SS_TOP + 60},
{" cmmd_rqsens", 2, SS_TOP + 62},
{" cmmd_tstrdy", 2, SS_TOP + 64},
{" cmmd_mdsens", 2, SS_TOP + 66},
{" cmmd_dummy", 2, SS_TOP + 68},
{" cmmd_rdiag", 2, SS_TOP + 74},
{" cmmd_sdiag", 2, SS_TOP + 76},
{" cmmd_addr", 2, SS_TOP + 70},
{" cmmd_mcast", 2, SS_TOP + 72},
{" mess_out", 2, SS_TOP + 52},
{" gotbus_rst", 2, SS_TOP + 78},
{" set_up", 2, SS_TOP + 50},
{" setbus_rst", 2, SS_TOP + 80},
};
#define NUM_OF_SE (28)
#define SE_TOP (186)
struct sts SCSI_ERROR[NUM_OF_SE] =
{
{" parity", 2, SE_TOP},
{"multiple_ids", 2, SE_TOP + 2},
{" cmmd_err1", 2, SE_TOP + 2 * 2},
{" cmmd_unknwn", 2, SE_TOP + 2 * 3},
{" cmmd_err2", 2, SE_TOP + 2 * 4},
{" cdms_to1", 2, SE_TOP + 2 * 5},
{" cdms_to2", 2, SE_TOP + 2 * 6},
{" cdms_to3", 2, SE_TOP + 2 * 7},
{" status_err", 2, SE_TOP + 2 * 8},
{" stms_to1", 2, SE_TOP + 2 * 9},
{" stms_to2", 2, SE_TOP + 2 * 10},
{" stms_to3", 2, SE_TOP + 2 * 11},
{" no_initresp", 2, SE_TOP + 2 * 13},
{" mssg_pre1", 2, SE_TOP + 2 * 14},
{" mssg_pre2", 2, SE_TOP + 2 * 15},
{"unkwnmsg_pre", 2, SE_TOP + 2 * 16},
{" mssg_post1", 2, SE_TOP + 2 * 17},
{" mssg_post2", 2, SE_TOP + 2 * 18},
{"unkwnmsg_pst", 2, SE_TOP + 2 * 19},
{" xmit_badlen", 2, SE_TOP + 2 * 20},
{" Out_DMAto1", 2, SE_TOP + 2 * 21},
{" Out_DMAto2", 2, SE_TOP + 2 * 22},
{" Out_DMAto3", 2, SE_TOP + 2 * 23},
{" In_DMAto1", 2, SE_TOP + 2 * 24},
{" In_DMAto2", 2, SE_TOP + 2 * 25},
{" no_maccon", 2, SE_TOP + 2 * 26},
{" ether_out", 2, SE_TOP + 2 * 27},
{" mssg_finish", 2, SE_TOP + 2 * 28},
};
#define NUM_OF_NS (4)
#define NS_TOP (246)
struct sts NET_STAT[NUM_OF_NS] =
{
{" Receives", 4, NS_TOP},
{" Transmits", 4, NS_TOP + 4},
{"Transmit req", 4, NS_TOP + 8},
{" Resets", 2, NS_TOP + 12},
};
#define NUM_OF_NE (15)
#define NE_TOP (244 + 16 + 2)
struct sts NET_ERROR[NUM_OF_NE] =
{
{" CRC Error", 2, NE_TOP + 2 * 8},
{" Frame Error", 2, NE_TOP + 2 * 7},
{"Missed Pckts", 2, NE_TOP + 2 * 9},
{" unexp_rst", 2, NE_TOP},
{" re_int", 2, NE_TOP + 2 * 2},
{" te_int", 2, NE_TOP + 2 * 3},
{" ow_int", 2, NE_TOP + 2 * 4},
{"cntovflw_int", 2, NE_TOP + 2 * 5},
{" dma_int", 2, NE_TOP + 2 * 6},
{" txto_in", 2, NE_TOP + 2 * 10},
{" txto_wrt", 2, NE_TOP + 2 * 11},
{" txon_ovflw", 2, NE_TOP + 2 * 13},
{" txin_ovflw", 2, NE_TOP + 2 * 14},
{" txwrt_ovflw", 2, NE_TOP + 2 * 15},
{"Transmit Err", 2, NE_TOP + 2},
};
unsigned char inq_buff[292];
int wrapping;
unsigned short get16 (unsigned char *);
unsigned long get32 (unsigned char *);
int search_ether_plus (char *name);
void print_scsi_stat (void);
void print_scsi_err (void);
void print_net_stat (void);
void print_net_err (void);
/************************************************
* *
************************************************/
int
main (int argc, char **argv)
{
int all, s, se, n, ne;
all = s = se = n = ne = 0;
if (argc > 1)
{
int c;
while ((c = getopt (argc, argv, "sSeE")) != EOF)
{
switch (c)
{
case 's':
n = 1;
break;
case 'S':
s = 1;
break;
case 'e':
ne = 1;
break;
case 'E':
se = 1;
break;
default:
break;
}
}
if (se + s + ne + n == 0)
all = 1;
if (optind < argc)
{
if (search_ether_plus (argv[optind]))
{
if (n || all)
print_net_stat ();
if (ne || all)
print_net_err ();
if (s || all)
print_scsi_stat ();
if (se || all)
print_scsi_err ();
return 0;
}
else
printf ("statistic: No such device %s\n", argv[optind]);
}
else
printf ("usage: statistic [-sSeE] device-name\n");
}
else
printf ("usage: statistic [-sSeE] device-name\n");
return 0;
}
/************************************************
* *
************************************************/
static unsigned short
get16 (unsigned char *src)
{
return (*src) + (*(src + 1) << 8);
}
/************************************************
* *
************************************************/
static unsigned long
get32 (unsigned char *src)
{
return (*src) + (*(src + 1) << 8) + (*(src + 2) << 16) + (*(src + 3) << 24);
}
/************************************************
* *
************************************************/
int
search_ether_plus (char *dev)
{
int ino;
char name[16];
if (!strchr (dev, '/'))
{
strcpy (name, "/dev/");
strcat (name, dev);
}
else
strcpy (name, dev);
if (ETDGetDriverVersion (name, &ino) < 0)
return 0;
if (!ETDGetStatistics (inq_buff, ino))
return 1;
return 0;
}
/************************************************
* *
************************************************/
void
print_net_stat (void)
{
int i;
if (wrapping)
printf ("\n");
wrapping = 1;
printf ("Ether+ Network Statistics\n");
for ( i = 0; i < (NUM_OF_NS + 1) / 2; i++)
{
struct sts *right, *left;
char *offset_l, *offset_r;
left = &NET_STAT[i]; right = &NET_STAT[i + NUM_OF_NS / 2];
offset_l = inq_buff + left->offset; offset_r = inq_buff + right->offset;
printf ("\t%s %8d %s %8d\n",
left->name, ((left->size == 4) ? get32 (offset_l) : get16 (offset_l)),
right->name, ((right->size == 4) ? get32 (offset_r) : get16 (offset_r)));
}
return;
}
/************************************************
* *
************************************************/
void
print_net_err (void)
{
int i;
if (wrapping)
printf ("\n");
wrapping = 1;
printf ("Ether+ Network Errors\n");
for ( i = 0; i < (NUM_OF_NE + 1) / 2; i++)
{
struct sts *right, *left;
char *offset_l, *offset_r;
left = &NET_ERROR[i]; right = &NET_ERROR[i + NUM_OF_NE / 2];
offset_l = inq_buff + left->offset; offset_r = inq_buff + right->offset;
printf ("\t%s %8d %s %8d\n",
left->name, ((left->size == 4) ? get32 (offset_l) : get16 (offset_l)),
right->name, ((right->size == 4) ? get32 (offset_r) : get16 (offset_r)));
}
return;
}
/************************************************
* *
************************************************/
void
print_scsi_stat (void)
{
int i;
if (wrapping)
printf ("\n");
wrapping = 1;
printf ("Ether+ SCSI Statistics\n");
for ( i = 0; i < (NUM_OF_SS + 1) / 2; i++)
{
struct sts *right, *left;
char *offset_l, *offset_r;
left = &SCSI_STAT[i]; right = &SCSI_STAT[i + NUM_OF_SS / 2];
offset_l = inq_buff + left->offset; offset_r = inq_buff + right->offset;
printf ("\t%s %8d %s %8d\n",
left->name, ((left->size == 4) ? get32 (offset_l) : get16 (offset_l)),
right->name, ((right->size == 4) ? get32 (offset_r) : get16 (offset_r)));
}
return;
}
/************************************************
* *
************************************************/
void
print_scsi_err (void)
{
int i;
if (wrapping)
printf ("\n");
wrapping = 1;
printf ("Ether+ SCSI Errors\n");
for ( i = 0; i < (NUM_OF_SE + 1) / 2; i++)
{
struct sts *right, *left;
char *offset_l, *offset_r;
left = &SCSI_ERROR[i]; right = &SCSI_ERROR[i + NUM_OF_SE / 2];
offset_l = inq_buff + left->offset; offset_r = inq_buff + right->offset;
printf ("\t%s %8d %s %8d\n",
left->name, ((left->size == 4) ? get32 (offset_l) : get16 (offset_l)),
right->name, ((right->size == 4) ? get32 (offset_r) : get16 (offset_r)));
}
return;
}